package com.lanqiao.companymanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanqiao.companymanage.entity.User;
import com.lanqiao.companymanage.service.StaffSalaryService;
import com.lanqiao.companymanage.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 何小棍
 * 职工工资管理与添加
 */
@RestController
@RequestMapping("/staffSalary")
@Api(tags = "职工工资管理")
public class StaffSalaryController {

    @Autowired
    StaffSalaryService staffSalaryService;


    /**
     * 职工工资分页查询
     */
    @GetMapping("/staffSalaryPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数,默认第一页"),
            @ApiImplicitParam(name = "size", value = "每页显示条数，默认 10")})
    @ApiOperation(value = "职工工资分页查询")
    public Object userPage(Page<User> userPage){
        IPage<User> page =  staffSalaryService.listPage(userPage);
        return Result.success(page);
    }


    /**
     * 职工工资添加
     * @param user
     * @return
     */
    @PostMapping("/addStaffSalary")
    @ApiOperation(value = "职工工资添加")
    public Result addStaffSalary(User user){
        int i = staffSalaryService.addStaffSalary(user);
        if (i==0) {
            return Result.err("添加失败");
        }else {
            return Result.success("添加成功",null);
        }
    }

    /**
     * 职工工资修改
     * @param user
     * @return
     */
    @PostMapping("/updateStaffSalary")
    @ApiOperation(value = "职工工资修改")
    public Result updateStaffSalary(User user){
        int i = staffSalaryService.updateStaffSalary(user);
        if (i==0) {
            return Result.err("修改失败");
        }else {
            return Result.success("修改成功",null);
        }
    }


    /**
     * 根据员工编号(userId)查询
     * @param userId
     * @return
     */
    @GetMapping("/selectById")
    @ApiOperation(value = "根据员工编号(userId)查询")
    public Object selectByUserId(Integer userId){
        User user = staffSalaryService.selectByUserId(userId);
        if (user == null) {
            return Result.err("找不到对应id的值");
        }else {
            return Result.success("查询成功",user);
        }
    }


    /**
     * 根据员工编号(userId)id删除
     */
    @GetMapping("/deletedByUserId")
    @ApiOperation(value = "根据员工编号(userId)id删除")
    public Object deletedByUserId(Integer userId)  {
        int i = staffSalaryService.deletedByUserId(userId);
        if (i==0) {
            return Result.err("删除失败");
        }else {
            return Result.success("删除成功",null);
        }
    }

}
